import matplotlib.pyplot as plt
import numpy as np
import statistics

data = []
lr5 = []
lr10 = []
lr15 = []
lr20 = []
for line in open('lr0.out'):
    data.append(float(line))
for line in open('lr5.out'):
    lr5.append(float(line))
for line in open('lr10.out'):
    lr10.append(float(line))
for line in open('lr15.out'):
    lr15.append(float(line))

print len(lr15)
print 'lr: 0% ==>'
print 'avg: %f' % statistics.mean(data)
print 'max: %f' % max(data)
print 'min: %f' % min(data)
print 'med: %f' % statistics.median(data)
print sorted(data)[284]

print 'lr: 5% ==>'
print 'avg: %f' % statistics.mean(lr5)
print 'max: %f' % max(lr5)
print 'min: %f' % min(lr5)
print 'med: %f' % statistics.median(lr5)
print sorted(lr5)[284]

print 'lr: 10% ==>'
print 'avg: %f' % statistics.mean(lr10)
print 'max: %f' % max(lr10)
print 'min: %f' % min(lr10)
print 'med: %f' % statistics.median(lr10)
print sorted(lr10)[284]

print 'lr: 15% ==>'
print 'avg: %f' % statistics.mean(lr15)
print 'max: %f' % max(lr15)
print 'min: %f' % min(lr15)
print 'med: %f' % statistics.median(lr15)
print sorted(lr15)[284]

x = data
n = np.arange(1, len(x) + 1) / np.float(len(x))
Xs = np.sort(x)

# plt.figure()
fig, ax = plt.subplots(figsize=(6, 4))
ax.step(Xs, n, label='LR: 0%')
ax.step(np.sort(lr5), n, label='LR: 5%')
ax.step(np.sort(lr10), n, label='LR: 10%')
ax.step(np.sort(lr15), n, label='LR: 15%')

ax.grid(True)
ax.legend()
# ax.legend(loc='right')
# ax.set_title('CDF: Spine0 policy check')
# ax.set_title('CDF: Spine0 policy runnable check')
# ax.set_title('CDF: Spine0 model update')
# ax.set_title('CDF: Spine0 DFG construction')
# ax.set_title('CDF: Spine0 ssw finish time')
ax.set_xlabel('Time (s)')
plt.savefig('%s.png' % "out-cdf")
plt.show()